package top.guoyang.springboot3.controller.contact;

import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.guoyang.springboot3.annotation.Limit;
import top.guoyang.springboot3.base.PageBean;
import top.guoyang.springboot3.base.R;
import top.guoyang.springboot3.entity.TbContact.TbContact;
import top.guoyang.springboot3.service.lianxi.TbContactService;
import top.guoyang.springboot3.validate.CommonValidate;
import top.guoyang.springboot3.vo.PageVO;

@RestController
@RequestMapping("/contact")
@RequiredArgsConstructor
public class TbContactController {
    private final TbContactService tbContactService;

    @Limit(key = "/contact/insert", message = "不要频繁提交")
    @PostMapping("")
    public R<String> insert(@RequestBody @Validated(CommonValidate.Add.class) TbContact tbContact){
        return tbContactService.insert(tbContact);
    }
    @GetMapping("/{ps}/{pn}")
    public R<PageVO<TbContact>> query(TbContact tbContact,@PathVariable("ps")Long ps, @PathVariable("pn")Long pn){
        return tbContactService.query(tbContact, PageBean.instance(ps, pn));
    }
    @DeleteMapping("/{id}")
    public R<String> delete(@PathVariable("id") Integer id){return tbContactService.delete(id);
    }
    @PutMapping("")
    public R<String> update(@RequestBody @Validated(CommonValidate.Edit.class) TbContact tbContact){
        return tbContactService.update(tbContact);
    }
    @GetMapping("/{id}")
    public R<TbContact> queryById(@PathVariable("id") Integer id){
        return tbContactService.queryById(id);
    }
}
